Next | Prev | Up | Top | Contents | Index

Shared Memory Segments

IRIX allows you to map a segment of memory into the address spaces of two or more processes at once. The block of shared memory can be read concurrently, and possibly written, by all the processes that share it. There are two interfaces, one compatible with SVR4 UNIX and one unique to IRIX.


IRIX Shared Memory Arenas

IRIX supports a unique system of shared memory allocation. The purpose is to create a memory arena designed as the basis for high-speed, low-overhead communication between concurrent processes.

You create a shared memory segment with a call to usinit(). The argument to usinit() is a file pathname string. The file is created (if necessary) and mapped into a segment of memory in the calling process (for a description of mapping files into memory, see Chapter 4). The file, and hence the segment, may or may not continue to exist after the creating process ends. This, and many other options, can be set by calling usconfig() before calling usinit().

Once the memory segment exists, any other process can access it by calling usinit() with the same pathname string. If that process has access privileges to the specified file, the memory segment is made part of its address space and it, too, can read the memory space, and optionally write in it.

There is a set of memory-allocation library calls that you can use to suballocate memory within a shared arena allocated by usinit(). Equally important, IRIX support for semaphores, locks, and barriers is based on the use of arenas allocated with usinit().

For more information on usinit() and arenas, refer to Topics in IRIX Programming manual, and to the usinit(3p), usconfig(3p) and usmalloc(3p) reference pages. See also the sample code of "Interprocess Communication" in Appendix A. In addition, some of the special cases of usinit() are covered in Chapter 4 of this book.


SVR4-Compatible Shared Memory

IRIX supports shared memory library calls compatible with those in AT&T SVR4 UNIX. In this scheme, one process calls shmget() to create a segment of shared memory. In some ways the segment resembles a file more than it resembles memory, for example

A shared segment has an associated integer key. Any other process can present the key to shmat(). If the user and group ID of the calling process have access permission, the segment becomes part of the address space of the process. Its virtual address is returned, and the process can use it as memory. If the process has write access, it can update the segment as well as read it.

The SVR4 shared memory facility is useful between processes created by fork(), since they have separate address spaces. Processes created by sproc() share their entire address space by default.

For sample code and more information on SVR4-compatible shared memory, refer to Topics in IRIX Programming, and to the ipcst(1), shmget(2), shmctl(2), and stdipc(3) reference pages.

There is a family of memory-allocation library calls that you can use to suballocate memory within a shared segment (or within any other segment of memory). Refer to the amalloc(3p) reference page for details.

Tip: Use an SVR4-compatible shared memory segment if you require portability. Otherwise, the IRIX implementation is faster and more flexible for a real-time program.


Next | Prev | Up | Top | Contents | Index